<template>
	<view class="evaluate">
		<nav-bar title="评价"></nav-bar>
		<scroll-view scroll-y :style="{height:mainHeight,width:'100%'}">
			<view class="content">
				<evaluate-person ref="evaluatePerson" :evaluateTechDetail="evaluateTechDetail"
					:zyEvaluationRuleItemVos="zyEvaluationRuleItemVos"></evaluate-person>
			</view>
		</scroll-view>
		<view class="btn_edit flexJcac">
			<view class="btn_cont" @click="clickSubmitEva">
				提交评价
			</view>
		</view>
		<you-popup :popupVisible="tipsVisible" :showTitle="false" :showBtn="false" @popupClose="tipsVisible=false">
			<view slot="popupContent" class="popup-content">
				<view class="title">恭喜</view>
				<image style="width: 120rpx;height: 120rpx;"  src="../../static/images/counp.png"
					mode=""></image>
				<view style="font-size: 32rpx;font-weight: 600;">{{getcoupon}} X {{number}}张</view>
				<view class="popup-submit flexJcac" style="margin: 20px 0;">
					<view class="submit" @click="clickConfirmTimeout">确定</view>
				</view>
				<view class="">优惠券可在我的-优惠券查看</view>
			</view>
		</you-popup>
	</view>
</template>

<script>
	import NavBar from '@/components/nav-bar/index.vue'
	import EvaluatePerson from './components/evaluatePerson.vue'
	import YouPopup from '@/components/you-popup/index.vue'
	import api_order from '@/api/order'
	export default {
		components: {
			NavBar,
			EvaluatePerson,
			YouPopup
		},
		data() {
			return {
				mainHeight: '',
				orderId: '',
				evaluateList: {},
				evaluateTechDetail: {},
				zyEvaluationRuleItemVos: [],
				tipsVisible: false,
				// value1:'',
				// check:false,
				getcoupon: '',
				number:0,
			}
		},
		onLoad(options) {
			if (options.evaluateTechDetail) {
				this.evaluateTechDetail = JSON.parse(decodeURIComponent(options.evaluateTechDetail))
			}
			this.mainHeight = this.$store.getters.heightData.mainHeight
			this.orderId = options.id
			api_order.getByOrderId({
				orderId: options.id
			}).then(res => {
				this.evaluateList = res.data
				this.zyEvaluationRuleItemVos = res.data.zyEvaluationRuleItemVos
			})

		},
		methods: {
			confirmEvaluate(evaluateData) {
				console.log(evaluateData,this.evaluateTechDetail,'1111111');
				const params = {
					technicianId: this.evaluateTechDetail.id,
					orderId: this.orderId,
					orderItemId:this.evaluateTechDetail.orderItemId,
					...evaluateData
				}
					console.log(params, 'params');
				api_order.addEvaluateAndItem(params).then(res => {
					if (res.code !== 200) return
				
					if (this.evaluateList.ticketId) {
						this.getcoupon = this.evaluateList.couponName
						this.number = this.evaluateList.number
					}
					this.tipsVisible = true
				})
			},
			clickConfirmTimeout() {
				api_order.evaluationGitCoupon({
					"storeId": this.evaluateTechDetail.belongStoreId
				}).then(res => {
					if (res.code == 200) {
						uni.switchTab({
							url: '/pages/order/index'
						})
					}
				})
			},
			clickSubmitEva() {
				let evaluateData = this.$refs.evaluatePerson.getEvaluateData()
				if (evaluateData.zyTechnicianEvaluateItemDtos.length < this.zyEvaluationRuleItemVos.length) {
					uni.showToast({
						title: '请每条至少选择一个星！',
						icon: 'none'
					})
					return
				}
				this.zyEvaluationRuleItemVos.map(el => {
					evaluateData.zyTechnicianEvaluateItemDtos.map(y => {
						evaluateData.evaluationRuleId = el.evaluationRuleId
						// if (el.evaluateProblem == y.issue) {
						// 	// y.id = el.id
						// 	y.evaluationRuleId = el.evaluationRuleId
						// }
					})
				})
				this.confirmEvaluate(evaluateData)
			},
			// lotteryDraw() {
			// 	uni.navigateTo({
			// 		url:`/subPages/order/lotteryDraw`
			// 	})
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		margin: 24rpx;
		background: #fff;
		border-radius: 17rpx;
	}

	.btn_edit {
		position: fixed;
		width: 100%;
		bottom: 0;
		height: 148rpx;
		opacity: 1;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 13rpx #ADADAD;

		.btn_cont {
			width: 671rpx;
			height: 94rpx;
			opacity: 1;
			border-radius: 63rpx;
			background: #C27E15;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 10rpx 10rpx 10rpx 10rpx;
			font-size: 30rpx;
			font-weight: 500;
			letter-spacing: 0rpx;
			line-height: 43.44rpx;
			color: rgba(255, 255, 255, 1);
			text-align: left;
			vertical-align: top;
		}
	}

	.contain-text {
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;

		img {
			width: 200rpx;
			height: 200rpx;
		}
	}

	.meess {
		text-align: center;
	}

	.popup-content {
		padding-bottom: 40rpx;
		text-align: center;
		.title{
			font-weight: 600;
			font-size: 35rpx;
			text-align: center;
			width: 100%;
		}
	}

	.wdithBtn {
		width: 117rpx;
		color: #fff;
		background-color: #C27E15;
	}
</style>